using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.CommonWeb;
using NTTHAO.Web.BL.Contact;

public partial class admin_webparts_Plug_ins_Contact_ContactConfigInput : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSave.Value = btnSave2.Value = LanguageUtility.GetLanguageText("SAVE", Session);
        chkActive.Text = LanguageUtility.GetLanguageText("ACTIVE", Session);

        try
        {
            if (!IsPostBack && Request.QueryString["id"] != null)
            {
                int configID = Convert.ToInt32(Request.QueryString["id"]);
                ContactGroupConfig config = new ContactGroupConfig(configID);
                if (config.ID < 1)
                {
                    throw new Exception();
                }

                txtName.Text = config.Key;
                txtDescription.Text = config.Description;
                chkActive.Checked = config.Actived;
            }
        }
        catch
        {
            string redirectURL = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"];
            Response.Redirect(redirectURL, false);
            return;
        }
    }

    public void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            ContactGroupConfig config = null;
            if (Request.QueryString["id"] != null)
            {
                int cID = Convert.ToInt32(Request.QueryString["id"]);
                config = new ContactGroupConfig(cID);
            }
            else
            {
                config = new ContactGroupConfig();
                int gID = Convert.ToInt32(Request.QueryString["gid"]);
                config.GroupID = gID;
            }
            config.Key = txtName.Text.Trim();
            config.Description = txtDescription.Text.Trim();
            config.Actived = chkActive.Checked;

            if (Request.QueryString["id"] != null)
            {
                config.Update();
            }
            else
            {
                config.Insert();
            }
        }
        catch { }

        string redirectURL = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&action=configgroup&id=" + Request.QueryString["gid"];
        Response.Redirect(redirectURL, false);
        return;
    }
}
